﻿using System;
using System.Collections.Generic;
using System.Text;

namespace MarketSimulator.Utils.Maps
{
    public static class WorldMap
    {
        #region Properties
        
        /// <summary>
        /// List of available Cities.
        /// </summary>
        public static IList<City> Cities = new List<City>();

        /// <summary>
        /// List of available Routes
        /// </summary>
        public static IList<Route> Routes = new List<Route>();

        /// <summary>
        /// List of available Storage Facilities
        /// </summary>
        public static IList<StorageFacility> StorageFacilities = new List<StorageFacility>();

        #endregion
        
        #region Cities Methods

        /// <summary>
        /// Get City by Id.
        /// </summary>
        /// <param name="cityId"></param>
        /// <returns></returns>
        public static City GetCityById(long cityId)
        {
            foreach (var c in Cities)
            {
                if (c.Id == cityId)
                {
                    return c;
                }
            }
            return null;
        }

        /// <summary>
        /// Get City by Name.
        /// </summary>
        /// <param name="cityName"></param>
        /// <returns></returns>
        public static City GetCityByName(long cityName)
        {
            foreach (var c in Cities)
            {
                if (c.Name.Equals(cityName))
                {
                    return c;
                }
            }
            return null;
        }

        /// <summary>
        /// Get neighbor cities for a City
        /// </summary>
        /// <param name="cityId"></param>
        /// <returns></returns>
        public static IList<City> GetNeighborCities(long cityId)
        {
            IList<City> neighbors = new List<City>();
            foreach (var route in Routes)
            {
                if (route.CityA.Id == cityId)
                {
                    neighbors.Add(route.CityB);
                }
                else if (route.CityB.Id == cityId)
                {
                    neighbors.Add(route.CityA);
                }
            }
            return neighbors;
        }

        #endregion

    }
}
